package thread;

public class DeadlockExample {
    private static Object lock1 = new Object();
    private static String lock2 = new String("ds");

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            synchronized (lock1) {
                System.out.println("Thread 1: Holding lock 1...");
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                }
                System.out.println("Thread 1: Waiting for lock 2...");
                synchronized (lock2) {
                    System.out.println("Thread 1: Holding lock 1 and lock 2...");
                }
                try {
                    Thread.sleep(10000000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

//        Thread t2 = new Thread(() -> {
//            synchronized (lock2) {
//                System.out.println("Thread 2: Holding lock 2...");
//                try {
//                    Thread.sleep(10);
//                } catch (InterruptedException e) {
//                }
//                System.out.println("Thread 2: Waiting for lock 1...");
//                synchronized (lock1) {
//                    System.out.println("Thread 2: Holding lock 2 and lock 1...");
//                }
//            }
//        });
        t1.setName("陈勇最帅线程!");
//        t2.setName("老婆们线程!");

        t1.start();
        Thread.sleep(10000000);
//        t2.start();
    }
}
